package com.cn.serverline.lineicp.produce.controller;

import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import com.cn.serverline.lineicp.produce.entity.ProcessDescription;
import com.cn.serverline.lineicp.produce.entity.dto.*;
import com.cn.serverline.lineicp.produce.entity.vo.PartNumberVo;
import com.cn.serverline.lineicp.produce.entity.vo.ProcessStepVo;
import com.cn.serverline.lineicp.produce.service.IProcessDescriptionService;
import com.cn.serverline.lineicp.productionLine.entity.ProcessSteps;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 生产执行工艺描述 前端控制器
 * </p>
 *
 * @author 王烁
 * @since 2024-08-12
 */
@Api(tags = "生产执行")
@RestController
@RequestMapping("/teProcessDescription")
public class ProcessDescriptionController {

    @Autowired
    private IProcessDescriptionService processDescriptionService;

    @ApiOperation(value = "任务开工按钮")
    @PostMapping("/saveAssemblyTask")
    public ResponseData<String> getAssemblyTask(@Validated @RequestBody SaveAssemblyTaskDto saveAssemblyTaskDto) {
        processDescriptionService.savegetAssemblyTask(saveAssemblyTaskDto);
        return new SuccessResponseData<>("保存成功");
    }

    @ApiOperation(value = "生产执行 查询件号")
    @GetMapping("/getPartNumber")
    public ResponseData<List<PartNumberVo>> getPartNumber(@ApiParam(value = "总装下发ID", required = true) @RequestParam("automaticScheduleId") String automaticScheduleId) {
        List<PartNumberVo> processDescription = processDescriptionService.getPartNumber(automaticScheduleId);
        return new SuccessResponseData<List<PartNumberVo>>(processDescription);
    }

    @ApiOperation(value = "生产执行 件号、工艺描述")
    @GetMapping("/getProcessDescription")
    public ResponseData<List<ProcessSteps>> getProcessDescription(@ApiParam(value = "工序ID", required = true) @RequestParam("automaticScheduleId") String automaticScheduleId) {
        List<ProcessSteps> processDescription = processDescriptionService.getProcessDescription(automaticScheduleId);
        return new SuccessResponseData<List<ProcessSteps>>(processDescription);
    }

    @ApiOperation(value = "生产执行 查询工步所需")
    @GetMapping("/getProcessStepDetails")
    public ResponseData<List<ProcessStepVo>> getProcessStepDetails(@ApiParam(value = "生产描述id", required = true) @RequestParam("tpdId") Long tpdId) {
        return new SuccessResponseData<List<ProcessStepVo>>(processDescriptionService.getProcessStepDetails(tpdId));
    }

    @ApiOperation(value ="生产执行  总装保存单件任务号")
    @PostMapping("/updatePartNumber")
    public ResponseData<String> updatePartNumber(@Validated @RequestBody UpdatePartNumberDto updatePartNumberDto){
        processDescriptionService.updatePartNumber(updatePartNumberDto);
        return new SuccessResponseData<>("保存成功");
    }

    @ApiOperation(value = "生产执行 获取生产执行描述ID（烘烤配置原始记录、胶液配置原始记录）和查看每个件的工步是否完成")
    @PostMapping("/getProcessDescriptionId")
    public ResponseData<List<ProcessDescription>> getProcessDescriptionId(@Validated @RequestBody ProcessDescriptionIdDto processDescriptionId) {
        List<ProcessDescription> processDescription=processDescriptionService.getProcessDescriptionId(processDescriptionId);
        return new SuccessResponseData<List<ProcessDescription>>(processDescription);
    }
    @ApiOperation(value = "修改烘烤配置原始记录")
    @PostMapping("/roastRecords")
    public ResponseData roastRecords(@RequestBody @Validated RoastRecordsDto roastRecords){
        processDescriptionService.roastRecords(roastRecords);
        return new SuccessResponseData("修改成功");
    }

    @ApiOperation(value = "修改胶液配置原始记录")
    @PostMapping("/glueRecords")
    public ResponseData glueRecords(@RequestBody @Validated GlueRecordingDto glueRecordingDto){
        processDescriptionService.glueRecords(glueRecordingDto);
        return new SuccessResponseData("修改成功");
    }


    @ApiOperation(value = "生产执行 工步设备、工具参数采集")
    @PostMapping("/addProcessDescription")
    public ResponseData<?> addGather(@Validated @RequestBody GatherDto gatherDto) {
          processDescriptionService.addGather(gatherDto);
        return new SuccessResponseData<>("修改成功");
    }
    @ApiOperation(value = "生产执行 工步设备、工具参数数据矫正")
    @PostMapping("/addCorrection")
    public ResponseData<?> addCorrection(@Validated @RequestBody CorrectionDto correctionDto) {
        processDescriptionService.addCorrection(correctionDto);
        return new SuccessResponseData<>("修改成功");
    }

    @ApiOperation(value = "生产执行 编写工步组执行：报工、取消报工")
    @PostMapping("/deskCirculation")
    public ResponseData<?> deskCirculation(@Validated @RequestBody DeskCirculationDto deskCirculation) {
        processDescriptionService.deskCirculation(deskCirculation);
        return new SuccessResponseData<>("修改成功");
    }

    @ApiOperation(value = "生产执行 向下工位流转")
    @PostMapping("/updateProcessSteps")
    public ResponseData<String> updateStater(@Validated @RequestBody UpdateStaterDto updateStaterDto){
        processDescriptionService.updateProcessSteps(updateStaterDto);
        return new SuccessResponseData<>("修改成功");
    }
    @ApiOperation(value = "生产执行 总装绑定产品编号")
    @PostMapping("/bundleTheProduct")
    public ResponseData<?> bundleTheProduct(@Validated @RequestBody List<BundleTheProductDto> bundleTheProductDto) {
        processDescriptionService.bundleTheProduct(bundleTheProductDto);
        return new SuccessResponseData<>("修改成功");
    }
}
